import { post } from '../../axios/index'
import { useEffect, useState } from 'react'
import { DatePicker } from 'antd';
import './leftList.less'
function LeftList(props) {
    const [list, setList] = useState([])
    function getData(valStr){
        if(!valStr) {
            const nowDate = new Date()
            valStr = nowDate.getFullYear() + '-' + (nowDate.getMonth() + 1)+ '-' + nowDate.getDate()
        }
        post('/ck_electrical/api/getAtFileNames', {queryTimeStr: valStr, facilityId: props.id}).then(res => {
            if(res.data.status === '200') {
                let data = res.data.data
                setList(data)
                props.player(data[Object.keys(data)[0]])
            }
        })
    }

    useEffect(() => {
        getData()
    }, [])

    function onChange(val, valStr) {
        getData(valStr)
    }
    return <div className={`${props.className} left-list-his`}>
        <div className="title">视频列表</div>
        <DatePicker placeholder="请选择" onChange={onChange} />
        <div className="list-his-l">
        {
            Object.keys(list).map((item, index) => <div className={`row-item ${index < Object.keys(list).length - 1 ? 'btn-line' : ''}`} key={index} onClick={() => props.player(list[item])}>
                {item}
            </div>)
        }
        </div>
    </div>
}

export default LeftList